package com.ymx.darling.type;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.Month;

public class MonthHandler implements TypeHandler<Month> {
    @Override
    public Month getResult(ResultSet resultSet, int columIndex) throws SQLException {
        int month = resultSet.getInt(columIndex);
        return month == 0 ? null : Month.of(month);
    }

    @Override
    public void setParameter(PreparedStatement statement, Month value, int index) throws SQLException {
        statement.setInt(index, value.getValue());
    }
}
